package com.kaifamiao.list;

import java.util.ArrayList;
import java.util.List;

public class ListTest1 {

	public static void main(String[] args) {
		List<String> list = new ArrayList<>();
		System.out.println( list );
		list.add( "唐三藏" );
		list.add( "孙悟空" ); // Collection
		list.add( "猪八戒" );
		System.out.println( list );
		list.add( 1 ,  "白龙马" ); // List#add(int,E)
		System.out.println( list );
		
		List<String> x = new ArrayList<>();
		x.add( "唐三藏" );
		x.add( "菩提祖师" );
		
		list.addAll( 0 ,  x ); // List#addAll(int,Collection)
		System.out.println( list );
		
		String name = list.get( 1 ); // List#get(int)
		System.out.println( name );
		
		System.out.println( list.indexOf( "孙悟空" ) ); // List#indexOf(Object)
		System.out.println( list.indexOf( "孙行者" ) );
		
		System.out.println( list ); 
		
		int last = list.lastIndexOf( "唐三藏" ) ; // List#lastIndexOf(Object)
		System.out.println( last ); 
		
		list.remove( last ); // List#remove(int)
		System.out.println( list ); 
		
		list.set( 0 ,  "唐长老" ); // List#set(int,E)
		System.out.println( list ); 
		
		int begin = 2 ;
		int end = 5 ;
		// 截取 list 集合中 [ begin , end ) 之间的元素并返回新的 List集合
		List<String> sub = list.subList( begin ,  end ); // List#subList(int,int)
		System.out.println( sub );
		
	}

}
